<?php

/**
* A validation class
*
* The validation class is used to validate inputfields from login/register form.
*
* @author dmq (master@dmq.se)
*/

class Validation
{
	/**
	* function username()
	* @param string $username is the value that the user enters in the username field
	* @return boolean true | false depending if username match reg.exp
	*/
	public function username( $username )
	{
		return preg_match( "/^[a-z0-9_]{4,20}$/i", $username );
	}

	/**
	* function password()
	* @param string $password is the value that the user enters in the password field
	* @return boolean true | false depending if password match reg.exp
	*/
	public function password( $password )
	{
		return preg_match( "/^\S{6,20}$/i" , $password );
	}

	/**
	* function email()
	* @param string $email is the value that the user enters in the email field
	* @return boolean true/false depending if email match reg.exp
	*/
	public function email( $email )
	{
		return preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/i', $email );
	}

	/**
	* function maxPlayers()
	* @param string $maxPlayers is the value that the user choose in maxPlayers dropbox
	* @return boolean true/false depending if maxPlayers match reg.exp
	*/
	public function maxPlayers( $maxPlayers ) {
		return preg_match('/^[2-8]$/i', $maxPlayers );
	}
}
